package main

import "fmt"

func main()  {
	fmt.Println("222",addTwoNumbers(11,22)) 
}

func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
    head := &ListNode{0,nil}
    p,q,curr := l1,l2,head
    jinwei := 0
    for p!=nil || q!= nil {
        x := 0
        y := 0
        if p!=nil {
            x = p.Val
        }
        if q!=nil {
            y = q.Val
        }
        addRs := x + y + jinwei
        curr.Next = &ListNode{addRs%10, nil}
        curr = curr.Next
        if p!=nil {
            p = p.Next
        }else{
            p = nil
        }
        if q!=nil {
            q = q.Next
        }else{
            q = nil
        }
        if addRs>=10 {
            jinwei = 1
        } else {
            jinwei = 0
        }
    }
    if jinwei==1 {
        curr.Next = &ListNode{1,nil}
    }
    return head.Next
}


//解答此题需要了解链表数据结构 
